package com.hoshiicloud.mallshop.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.auth.vo.TokenUsersVO;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.mallshop.feign.ShopUserFeignService;
import com.hoshiicloud.mallshop.mapper.StoredProcedureMapper;
import com.hoshiicloud.mallshop.param.GetChildListParam;
import com.hoshiicloud.mallshop.service.ShopConsumersService;
import com.hoshiicloud.user.dto.userCenter.MemberDto;
import com.hoshiicloud.user.param.PlatStoreConsumerPageParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: hoshiicloud-biz
 * @description: 平台消费者服务实现类
 * @author: Mr.wu
 * @create: 2019-08-13 10:09
 **/
@Service
public class ShopConsumersServiceImpl implements ShopConsumersService {
    @Autowired
    private ShopUserFeignService userFeignService;

    @Autowired
    private StoredProcedureMapper storedProcedureMapper;



    @Override
    public Response<Page<MemberDto>> getStoreConsumersPage(PlatStoreConsumerPageParam param, TokenUsersVO tokenUsersVO) {
        //入参不传店铺id为查询所有与其相关店铺
        //如传参则只能查询与其相关店铺

        //查询分店主键
        GetChildListParam getChildListParam=new GetChildListParam(tokenUsersVO.getStoreId().toString(),"id","parent_id","plat_store");
       storedProcedureMapper.getChildListStr(getChildListParam);
        String storeIds=getChildListParam.getRetVal();
        if(StringUtils.isNotBlank(param.getStoreIds())){
            if(!storeIds.contains(param.getStoreIds())){
                //查询的店铺id与其无关,返回错误
                return Response.failed("查询权限不足");
            }
        }else{
            param.setStoreIds(storeIds);
        }
        return userFeignService.getStoreConsumersPage(param);
    }
}
